package com.tx.activemq._01_c_p._04_jms_dependence._041_persistent.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * 【producer】 topic 持久化
 */
public class TopicProducer {

    private static final String ACTIVEMQ_URL = "tcp://192.168.254.30:61616";

    private static final String TOPIC_NAME = "wechat";

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = factory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(TOPIC_NAME);

        MessageProducer producer = session.createProducer(topic);

        //持久化
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
//        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for (int i = 0; i < 3; i++) {
            TextMessage msg = session.createTextMessage("msg" + i);
            producer.send(msg);
        }

        producer.close();
        session.close();
        connection.close();
    }
}